
export  class Result<T> {
  result: number;
  message: string;
  data?: T;
  constructor(result: number, message: string, data?: T) {
    this.result = result;
    this.message = message;
    this.data = data;
  }
}


export const debounce = (fn: Function, delay: number) => {
  let timer: any;
  return function (this: any) {
    clearTimeout(timer);
    timer = setTimeout(() => {
      fn.apply(this, arguments);
    }, delay);
  };
};

const Debounce = (delay:number):MethodDecorator=>{
    return _debounce(delay);
}
function _debounce(delay:number):MethodDecorator {
  return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor)=>{
    const oldValue = descriptor.value
    descriptor.value = ()=>{
      debounce(oldValue,delay)
    }
  }
}

